package four.book.web;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import four.book.biz.UserBiz;
import four.book.entity.BookUser2;

/**
@author ��־
@version 1.0
<p>���ڣ�2018��12��17�� ����7:42:40</p>
 */
@Controller
@RequestMapping("/User")
public class UserController {
	@Resource
	private UserBiz userBiz;

	@RequestMapping("/tologin.do")
	public String  tologin(){
		return "login";
	}
	@RequestMapping("/toReg.do")
	public String toReg(){
		return "register";
	}
	@RequestMapping("/toHome.do")
	public String toHome(){
		return "Homepage";
	}
	/**
	 * 用户登录验证
	 * @param user
	 * @return
	 */
	@RequestMapping(value="/login.do",method=RequestMethod.POST)
	public ModelAndView UserLogin(BookUser2 user,HttpSession session){
		BookUser2 us= userBiz.getuser(user.getName());
		ModelAndView mv1=new ModelAndView("Homepage");
		ModelAndView mv2=new ModelAndView("login");
		if(us!=null&&us.getUserpass().equals(user.getUserpass())){
			session.setAttribute("USER", us);
			return mv1;
		}else{
			return mv2;
		}
	}
	/**
	 * 注册用户
	 * @param user
	 * @return
	 */
	@RequestMapping(value="/register.do",method=RequestMethod.POST)
	public String UserRegister(BookUser2 user){
		userBiz.adduser(user);
		return "login";
	}
	/*
	public String CheckUser(){
		
	}*/
	
}
